define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'back_stage_robot_work_sum/index' + location.search,
                    // add_url: 'back_stage_robot_work_sum/add',
                    // edit_url: 'back_stage_robot_work_sum/edit',
                    // del_url: 'back_stage_robot_work_sum/del',
                    // multi_url: 'back_stage_robot_work_sum/multi',
                    // import_url: 'back_stage_robot_work_sum/import',
                    table: 'back_stage_robot_work_sum',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'agentId',
                sortName: 'recordDate',
                fixedColumns: true,
                fixedRightNumber: 1,
                templateView: false,
                clickToSelect: false,
                search: false,
                showColumns: false,
                showToggle: false,
                showExport: false,
                showSearch: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'agentid',
                            title: __('AgentId'),
                            searchList: Config.adminUserList,
                            defaultValue: $("#loginUserId").val(),
                            operate: 'FIND_IN_SET',
                            formatter: Table.api.formatter.label
                        },

                        {field: 'agencyregion', title: __('agencyregion'), operate: false},

                        {
                            field: 'recordDate',
                            title: __('Date'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.date,
                        },

                        {field: 'checknum', title: __('Daily verifiied number'), operate: false},

                        {field: 'ipaddr', title: __('current ip'), operate: false},

                        {field: 'status', title: __('current state'), operate: false},
                        /*
                        {
                            field: 'state', title: __('current state'), formatter: function (value) {
                                if (value == 1)
                                    return "normal";
                                else if (value == 9)
                                    return "delete";
                            }, operate: false
                        },
                        */

                       // {field: 'lastworktime', title: __('Latest working hours'), operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'checkrobot',
                                    text: __('Setting'),
                                    title: __('Setting'),
                                    classname: 'btn btn-xs btn-success btn-dialog btn-checkrobot checkrobot',
                                    refresh: true,
                                    url: "back_stage_robot_work_sum/checkrobot?agentId={agentid}"
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        checkrobot: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
